package process

import (
	"encoding/json"
	amqp "github.com/rabbitmq/amqp091-go"
	"go.uber.org/zap"
	"go_es/server/global"
	"go_es/server/model"
	"go_es/server/service"
)

type AuthAdminProcess struct {}

func (ap *AuthAdminProcess) InsertEs()  {
	rabbit := service.NewRabbitMQ("go_es", "auth_admin", "auth_admin_queue")
	// 执行消费
	rabbit.Consume(func(d amqp.Delivery) {
		var authAdmins []model.AuthAdmin
		err := json.Unmarshal([]byte(d.Body), &authAdmins)
		if err != nil {
			global.GVA_LOG.Error("auth_admin:从rabbitMQ中解析数据失败", zap.String("auth_admin", err.Error()))
		}
		for _, admin := range authAdmins {
			service.ServiceGroupApp.Put("auth_admin", admin)
		}
	})
}

